package chz.emarket.web.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import chz.emarket.dao.ContentDao;
import chz.emarket.model.Content;
import chz.emarket.model.Person;

@Controller
public class HomeController {
	
	@Autowired
	private ContentDao contentdao;
	
	@RequestMapping({"/","/index","/home"})
	public String showHomePage(HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		HttpSession session = request.getSession();
		
		Person user = (Person)session.getAttribute("user");
		if(null != user) {
			System.out.println("user from session" + user.toString());
			model.addAttribute("user", user);
		} else {
			System.out.println("no logined");
		}
		
		List<Content> productList = contentdao.getContentList();
		model.addAttribute("productList", productList);
		
		return "index";
	}

}
